package org.jprogger.myworld.api.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jprogger.myworld.api.ApiServiceInvocationException;
import org.jprogger.myworld.api.app.AppContext;
import org.jprogger.myworld.api.model.User;
import org.jprogger.myworld.api.response.ApiResponse;
import org.jprogger.myworld.api.response.handler.HasAppPermApiResponseHandler;
import org.jprogger.myworld.api.response.handler.GetListUserInfoApiResponseHandler;
import org.jprogger.myworld.api.response.handler.IsAppUserApiResponseHandler;


/**
 * 
 * @author jprogger
 *
 */
public class UserService extends BaseApiService {
	
	public UserService(AppContext context) {
		super(context);
	}
	
	public ApiResponse<List<User>> getUsersInfo(String[] userIds, int userId) 
			throws ApiServiceInvocationException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("uid", userId);
		params.put("uids", userIds);
		params.put("method", "users.getInfo");
		return apiCall(params, new GetListUserInfoApiResponseHandler());
	}
	
	public ApiResponse<Integer> isAppUser(String userId) 
			throws ApiServiceInvocationException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("uid", userId);
		params.put("method", "users.isAppUser");
		return apiCall(params, new IsAppUserApiResponseHandler());
	}
	
	public ApiResponse<Integer> isAppHasPermissions(String userId, String extPerm)
			throws ApiServiceInvocationException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("uid", userId);
		params.put("ext_perm", extPerm);
		params.put("method", "users.hasAppPermission");
		return apiCall(params, new HasAppPermApiResponseHandler());
	}
}
